package com.easonji.admin.controller;

import java.util.List;

import javax.annotation.Resource;

import com.easonji.admin.manager.AppManager;
import com.easonji.admin.manager.PermissionManager;
import com.easonji.admin.service.DeptService;
import com.easonji.admin.service.PermissionService;
import com.easonji.admin.service.RoleService;
import com.easonji.common.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easonji.common.node.TreeNode;

/**
 * @ClassName: TreeController
 * @Description: 树控制器
 * @Author: LiuJun
 * @date: 2018/07/22 17:30
 * @Version: 1.0
 * @Copyright: Copyright (c) 2018 - 2019
 */
@Controller
@RequestMapping("/tree")
public class TreeController extends BaseController {

    @Resource
    private DeptService deptService;

    @Resource
    private PermissionService permissionService;

    @Resource
    private RoleService roleService;

    @Resource
    private PermissionManager permissionManager;

    @Resource
    private AppManager appManager;

    /**
     * 获取部门的tree列表
     */
    @ResponseBody
    @PostMapping("/dept")
    public List<TreeNode> queryDeptTreeNode() {
        List<TreeNode> treeNodes = deptService.queryDeptTreeNode();
        return treeNodes;
    }

    /**
     * 获取菜单列表
     */
    @ResponseBody
    @PostMapping(value = "/permission/app/{appId}")
    public List<TreeNode> queryPermissionTreeNodeByAppId(@PathVariable Integer appId) {
        return permissionManager.queryPermissionTreeNodeByAppId(appId);
    }

    /**
     * 获取角色菜单列表
     */
    @ResponseBody
    @PostMapping(value = "/permission/role/{roleId}")
    public List<TreeNode> queryPermissionTreeNodeByRoleId(@PathVariable Integer roleId) {
        return permissionManager.queryPermissionTreeNodeByRoleId(roleId);
    }

    /**
     * 获取用户应用列表
     */
    @ResponseBody
    @PostMapping("/app")
    public List<TreeNode> appTree() {
        return appManager.queryAppTreeNodes();
    }

    /**
     * 获取用户应用列表
     */
    @ResponseBody
    @PostMapping("/app/{userId}")
    public List<TreeNode> appTree(@PathVariable Integer userId) {
        return appManager.queryAppTreeNodesByUserId(userId);
    }

    /**
     * 获取用户角色列表
     */
    @ResponseBody
    @PostMapping("/role/{userId}")
    public List<TreeNode> roleTree(@PathVariable Integer userId) {
        return roleService.queryRoleTreeNode(userId);
    }
}
